package com.manager.action.user;

import java.util.List;

import javax.xml.registry.infomodel.User;

import org.common.util.TranslateHelper;
import org.wface.web.core.ActionSupport;

import com.manager.service.user.UserService;
import com.web.model.Userinfo;
import com.web.model.vo.UserinfoVo;
import com.web.tag.bean.PageModel;

public class UserAction extends ActionSupport{
   
	private String id;
	private String page;

	private String classid;
	private String title;

	public String list() {
		PageModel model = new PageModel();
		int pageNum = TranslateHelper.parseInteger(page);
		model.setPageNum(pageNum);
        
		UserinfoVo query=new UserinfoVo();
		UserService userService = new UserService();
		List<Userinfo> user = userService.findList(model, query);
		getRequest().setAttribute("users", user);  
		model.setPaths(getBasePath() + "/manager/users/list.do?");
		getRequest().setAttribute(PageModel.PAGEMODEL, model);
		return "list";
	}

	private String getBasePath() {
		String basePath = getRequest().getScheme() + "://" + getRequest().getServerName() + ":" + getRequest().getServerPort() + getRequest().getContextPath();
		return basePath;
	}

	public String create() { 
		return "create";
	}

	 

	public void setId(String id) {
		this.id = id;
	}

	public String edit() { 
		UserService userService = new UserService();
		Userinfo obj=userService.getById(TranslateHelper.parseInteger(id));
		getRequest().setAttribute("userinfo", obj); 
		return create();
	}

	public String delete() { 
		UserService userService = new UserService();
		userService.deleteUserinfo(TranslateHelper.parseInteger(id));
		return "!/manager/users/list.do";
	}
    
}
